<!-- BlogPost.vue -->
<template>
  <div class="post" :class="isFeatured()">
    <a href="#">
      <div class="image" :style="{ backgroundImage: `url(${imageUrl})` }">
        <div class="time">
          <div class="date">{{ date }}</div>
          <div class="month">{{ month }}</div>
        </div>
      </div>
      <div class="content">
        <h1>{{ title }}</h1>
        <p>{{ content }}</p>
        <div class="meta">
          <span class="icon-comment">{{ comments }} Comments</span>
          <ul class="tags">
            <li v-for="(tag, tagIndex) in tags" :key="tagIndex">{{ tag }}</li>
          </ul>
        </div>
      </div>
    </a>
  </div>
</template>

<script setup>
import { defineProps } from 'vue';

const props = defineProps({
  isFeatured: {
    type: Boolean,
    default: false
  },
  imageUrl: {
    type: String,
    required: true
  },
  date: {
    type: Number,
    required: true
  },
  month: {
    type: String,
    required: true
  },
  title: {
    type: String,
    required: true
  },
  content: {
    type: String,
    required: true
  },
  comments: {
    type: Number,
    required: true
  },
  tags: {
    type: Array,
    default: () => []
  }
});
const isFeatured = () => props.isFeatured? 'featured' : 'subFeature';
</script>

<style scoped lang="scss">
@mixin transform($value) {
  -webkit-transform: $value;
  -moz-transform: $value;
  -ms-transform: $value;
  -o-transform: $value;
  transform: $value;
}

@mixin box-shadow($shadow) {
  box-shadow: $shadow;
}

@mixin transition($props) {
  transition: $props;
}

$text-color: #444;
$icon-color: #3498db;
$white-color: #fff;

$blog--height: 200px;

.post {
  flex: 1;
  overflow: hidden;
  background: $white-color;
  height: $blog--height;
  @include box-shadow(0 0 2px 0 rgba(0, 0, 0, 0.2));
  margin-right: 1em;
  margin-bottom: 1em;

  &:hover {
    @include box-shadow(0 0 3px 2px rgba(0, 0, 0, 0.1));
    .image {
      opacity: 0.8;
    }
  }

  .image,
  .content {
    display: inline-block;
    position: relative;
    @include transition(all 500ms ease);
  }

  .image {
    float: left;
    width: 50%;
    height: $blog--height;
    background-size: cover;
    background-position: center center;

    .time {
      background: rgba($white-color, 0.5);
      width: 50px;
      text-align: center;
      padding: 0.5em 0;
      color: $text-color;

      .date {
        font-weight: bolder;
      }

      .month {
        font-size: 0.7rem;
      }
    }
  }

  .content {
    padding: 0.5em 1em;
    width: 50%;
    @include box-shadow(-2px 0 2px -1px rgba(0, 0, 0, 0.1));
    height: $blog--height;

    &:before {
      content: '';
      position: absolute;
      background: $white-color;
      width: 10px;
      height: 10px;
      top: 20%;
      left: -5px;
      @include transform(rotate(45deg));
      @include box-shadow(-1px 0 2px -1px rgba(0, 0, 0, 0.1));
    }

    h1 {
      font-weight: 600;
      line-height: 2;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    p {
      font-weight: 300;
      font-size: 0.7rem;
      line-height: 1.5;
      margin-bottom: 0.5em;
      font-family: 'Merriweather', sans-serif;
    }

    .meta {
      .icon-comment {
        font-size: 0.7em;
        line-height: 2;
        margin-top: auto;
      }

      .tags {
        list-style: none;
        padding: 0;
      }
    }
  }

  &.featured {
    margin: 0.5em 0 1em 0;
    grid-column-end: span 4;

    .image {
      height: 250px;
    }

    .content {
      height: 250px;
    }
  }
}
.subFeature{
  grid-column-end: span 2;
}
</style>
